package com.wxmit.framework.excel.domain;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.wxmit.base.enums.YesOrNoEnum;
import com.wxmit.framework.excel.annotation.ExcelCellSelect;
import com.wxmit.framework.excel.converter.StatusConverterContext;
import com.wxmit.framework.excel.handler.SexConverterContext;
import com.wxmit.framework.excel.handler.StatusCellSelectFieldHandler;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author huangxiong
 * @date 2022/12/23
 */
@Data
@Accessors(chain = false)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExcelDemo {

    @ExcelProperty(value = "姓名",index = 0)
    @NotNull(message = "姓名不能为空！")
    private String name;

    // 通过 SexConverterContext 进行转换
    @ExcelProperty(value = "性别",converter = SexConverterContext.class,index = 1)
    @ExcelCellSelect(value = {"男","女"})
    private String sex;

    @ExcelProperty(value = "出生日期",index = 2)
    @DateTimeFormat("yyyy-MM-dd")
    private Date birthday;

    @ExcelProperty(value = "状态",converter = StatusConverterContext.class,index = 3)
    @ExcelCellSelect(handler = StatusCellSelectFieldHandler.class)
    private String status;

    public static List<ExcelDemo> data(){
        List<ExcelDemo> list = new ArrayList<>();

        list.add(
                ExcelDemo.builder().name("刘德华1").sex("0").status(YesOrNoEnum.YES.code).birthday(new Date()).build()
        );
        list.add(
                ExcelDemo.builder().name("刘德华2").sex("0").status(YesOrNoEnum.YES.code).birthday(new Date()).build()
        );
        list.add(
                ExcelDemo.builder().name("刘德华3").sex("1").status(YesOrNoEnum.YES.code).birthday(new Date()).build()
        );

        return list;
    }
}
